#include "main/utils.h"
#include "lib/binary_tree.h"
using namespace std;

void sum(BinaryTreeNode* root, int cur_sum, int &total_sum) {
  if (!root) {
    return;
  }
  cur_sum = cur_sum * 10 + root->value;
  if (!root->left && !root->right) {
    total_sum += cur_sum;
    return;
  }
  sum(root->left, cur_sum, total_sum);
  sum(root->right, cur_sum, total_sum);
}

int sum1(BinaryTreeNode* root, int cur_sum) {
  if (!root) {
    return 0;
  }
  cur_sum = cur_sum * 10 + root->value;
  if (!root->left && !root->right) {
    return cur_sum;
  }
  return sum1(root->left, cur_sum) + sum1(root->right, cur_sum);
}

int main() {
  vector<int> vec = {3, 9, 0, 5, 1, 2};
  BinaryTreeNode* root = CreateBinaryTree(vec);
  int cur_path = 0, total_path = 0;
  sum(root, cur_path, total_path);
  cout << total_path << endl;

  int cur_path1 = 0;
  int ret = sum1(root, cur_path1);
  cout << ret << endl;

  return 0;
}
